package com.example.myapplication2030606131;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;

import androidx.annotation.VisibleForTesting;
import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {

    private TextView textView;
    private RadioGroup radioGroup2;
    private RadioButton radioMainJiaoche;
    private RadioButton radioMainMPV;
    private RadioButton radioMainSUV;
    private RadioButton radioMainLine1;
    private RadioButton radioMainLine2;
    private RadioButton radioMainLine3;
    private RadioButton radioMainLine4;
    private Button brnMainChaungjian;
    private RadioGroup radioMainLine;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
        radioGroup2.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int i) {
                RadioButton radioButton = findViewById(i);
                Log.i("RadioButton ", radioButton.getText().toString());
            }
        });
        radioMainLine.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int i) {
                RadioButton radioButton =findViewById(i);
                Log.i("RadioButton ", radioButton.getText().toString());
            }
        });
        brnMainChaungjian.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String msg = "";
                int carId=radioGroup2.getCheckedRadioButtonId();
                if (carId !=-1){
                    msg=((RadioButton)findViewById(carId)).getText().toString();
                }else {
                    msg="未输入车型";
                }
                int lineId=radioMainLine.getCheckedRadioButtonId();
                if (lineId !=-1){
                    msg+=","+((RadioButton)findViewById(lineId)).getText().toString();
                }else {
                     msg+="未选生产线";
                }
                Log.i("点击按钮 ",msg);
            }
        });
    }

    private void initView() {
        textView = (TextView) findViewById(R.id.textView);
        radioGroup2 = (RadioGroup) findViewById(R.id.radioGroup2);
        radioMainJiaoche = (RadioButton) findViewById(R.id.radio_main_jiaoche);
        radioMainMPV = (RadioButton) findViewById(R.id.radio_main_MPV);
        radioMainSUV = (RadioButton) findViewById(R.id.radio_main_SUV);
        radioMainLine1 = (RadioButton) findViewById(R.id.radio_main_line1);
        radioMainLine2 = (RadioButton) findViewById(R.id.radio_main_line2);
        radioMainLine3 = (RadioButton) findViewById(R.id.radio_main_line3);
        radioMainLine4 = (RadioButton) findViewById(R.id.radio_main_line4);
        brnMainChaungjian = (Button) findViewById(R.id.brn_main_chaungjian);
        radioMainLine = (RadioGroup) findViewById(R.id.radio_main_line);
    }
}